﻿using HalconDotNet;
using Halcon二次开发.Controller.主界面交互;
using Halcon二次开发.Model;
using Halcon二次开发.Model.自定义控件;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.工位监控画面
{
    public partial class MonitoringForm : Form
    {

        /// <summary>
        /// 单例模式
        /// </summary>
        private MonitoringForm()
        {
            InitializeComponent();
        }
        //所有实时监控画面的对象
        public List<FramesTimeForm> framesUserContorls = new List<FramesTimeForm>();

        private static MonitoringForm monitoringForm ;
        /// <summary>
        /// 单例模式设计
        /// </summary>
        /// <returns></returns>
        public static MonitoringForm GetMonitoringForm()
        {
            if (monitoringForm == null)
            {
                monitoringForm = new MonitoringForm();
            }
            return monitoringForm;
        }

        private void MonitoringForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }
       
        /// <summary>
        /// 加工位画面加载到窗体上
        /// </summary>
        public void AddFramesTime(HwindowFlowNodeUrseControl hwindowFlowNodeUrse)
        {
            //string srts=hwindowFlowNodeUrse.name;
            //framesUserContorls.Add(new FramesTimeForm(hwindowFlowNodeUrse,this));
        }
        //横向排序窗体
        private void 横向排列ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal); //使用MdiLayout枚举实现窗体的水平平铺
        }
        //纵向排序窗体
        private void 纵向排列ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical); //使用MdiLayout枚举实现窗体的垂直平铺
        }
        /// <summary>
        /// 获取当前实时监控对象
        /// </summary>
        /// <returns></returns>
        public FramesTimeForm GetHSmartWindow(string name)
        {
            int length = framesUserContorls.Count;
            foreach (FramesTimeForm item in framesUserContorls)
            {
                if (item.name.Equals(name))
                {
                    return item;
                }
            }
            return null;
        }
        /// <summary>
        ///  释放以删除的窗体
        /// </summary>
        public void DelForms(string name)
        {
            foreach (FramesTimeForm child in this.MdiChildren)
            {
                if (child.name == name) // 替换为你要关闭的子窗体的名称
                {
                    child.Close();
                    break; // 如果只需关闭一个，则找到后退出循环
                }
            }
        }
        /// <summary>
        /// 切换工程时删除
        /// </summary>
        /// <param name="name"></param>
        public void VerifyDelProject(string name)
        {
            try
            {
                //清空MDI容器
                foreach (FramesTimeForm child in this.MdiChildren)
                {
                    if (child.Text == name) // 替换为你要关闭的子窗体的名称
                    {
                        child.Close();
                        break; // 如果只需关闭一个，则找到后退出循环
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        
    }
}
